﻿@{
    Ajax.Dna().Widget()
        .UserPreferences(@<text>
    @if (HttpContext.Current.User.IsAdministrator())
    { 
        <div style="overflow: hidden;">
            @item.PropertyDescriptors["DataSourceUrl"].DisplayName</div>
        <div style="overflow: hidden; margin-top: 5px;">
            @(Ajax.Dna().TextBox(item.GenerateFieldID("DataSourceUrl"))
                    .Value(item.UserPreferences["DataSourceUrl"] != null ? item.UserPreferences["DataSourceUrl"].ToString() : "http://")
                    .GetHtml()
            )
        </div>
        <div  style="overflow: hidden; margin-top: 5px;">
        @(Ajax.Dna().Button(item.GenerateFieldID("btnBrowse"))
        .LocText("RES_BROWSE")
            .Click("$dna.fileDlg(\""+Url.Action("Dialog", "WebFiles", new { Area = "", website = WebSiteContext.Current.Web.Name })+"\",\"#" + item.GenerateFieldID("DataSourceUrl") + "\");")
        .ImageIcons(Url.Content("~/content/images/icon_folder_open_16.gif"))
        .GetHtml())
        </div>
        <hr />
    }
    </text>)
        .Content(widget =>
        {

            if (!string.IsNullOrEmpty(widget.UserPreferences["DataSourceUrl"] as string))
            {
                Ajax.Dna()
                    .TreeView(widget.GenerateFieldID("TreeView"))
                    .ExpandedLevel(1)
                    .SinglePathExpand(true)
                    .Bind(widget.UserPreferences["DataSourceUrl"].ToString(), false)
                    .Render();
            }
        })
        .Preview(widget=>{
            Ajax.Dna().TreeView(widget.GenerateFieldID("TreeView"))
                .Items(items=>{
                    items.Add("Root", "javascript:void(0);").Items(subNodes => {
                        subNodes.Add("Sub node item1", "javascript:void(0);");
                        subNodes.Add("Sub node item2", "javascript:void(0);");
                        subNodes.Add("Sub node item3", "javascript:void(0);");
                        subNodes.Add("Sub node item4", "javascript:void(0);");
                    });
                })
                .Render();
        
        })
        .Render();
}
